Skip to content

fix(eval): acknowledge sync only after preceding writes complete 🤖🤖🤖 - #282

Open
Sampoornnagpal wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
Sampoornnagpal:fix/eval-sync-write-barrier
Open

fix(eval): acknowledge sync only after preceding writes complete 🤖🤖🤖#282
Sampoornnagpal wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
Sampoornnagpal:fix/eval-sync-write-barrier

Conversation

@Sampoornnagpal

@Sampoornnagpal Sampoornnagpal commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

During batch collection, the headless backend acknowledges a queued /v1/sync event before writing the preceding batch. Scorers can receive {"synced": true} while that batch is still blocked and absent from storage.

Stop collection at the barrier, write the batch, then resolve the waiting request. Use a future carrying write success so failed batches or payloads skipped by the store return HTTP 500 on subsequent sync requests. Since skipped data cannot be recovered by syncing again, failure remains latched for that backend's lifetime. Cancelled/timed-out callers do not stop the worker. Shutdown also drains in-flight work when the queue is already empty.

Validation

Deterministic tests coordinate blocked writers with events, without timing sleeps. They cover batch limits 1 and 32, later arrivals, exceptions, skipped payloads, and cancelled sync requests. The pre-fix run reproduced premature acknowledgement and false success after a write exception.

uv run pytest -q util/eval_pipeline/tests/test_headless_sync.py tests/tracing/test_journal_routes_match.py — 7 passed. Targeted Pyright: 0 errors/warnings.

These exercise the ASGI app with a controlled writer, without a live server/model. Windows/Python 3.12 uses external import-only helpers for #84/#85 (fcntl/SIGUSR2); these are not included and do not validate POSIX locking/signals.

Related issues

Independent of the trace-store connection/transaction changes in #273/#274.

Checklist

  • Ruff lint and formatting pass.
  • Concurrency regression and route contract tests pass.
  • Sync docstring describes the barrier and failure behavior.
  • Existing/new SPDX headers present.

Summary by CodeRabbit

  • Bug Fixes
    • Synchronization now waits for all previously queued ingestion batches to finish before responding.
    • Synchronization reports an HTTP 500 error when trace data fails to persist or is skipped.
    • Improved reliability when synchronization requests are cancelled.
    • Shutdown now waits for pending ingestion work to complete, helping prevent data loss.

Signed-off-by: Sampoorn Nagpal <nagpalsampoorn@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 85a500ac-251c-4876-91ce-83d6fff883a8

📥 Commits

Reviewing files that changed from the base of the PR and between 0bcdf54 and 8704338.

📒 Files selected for processing (2)
  • util/eval_pipeline/src/eval_pipeline/headless_backend.py
  • util/eval_pipeline/tests/test_headless_sync.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • util/eval_pipeline/tests/test_headless_sync.py
  • util/eval_pipeline/src/eval_pipeline/headless_backend.py

Included review availability: Your plan provides up to 12 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The headless ingestion worker now uses future barriers, tracks persistence failures, handles cancelled requests, and drains queued work during shutdown. /v1/sync returns HTTP 500 after prior writes fail. Tests cover ordering, failures, skipped payloads, and cancellation.

Changes

Headless synchronization

Layer / File(s) Summary
Future barriers and worker draining
util/eval_pipeline/src/eval_pipeline/headless_backend.py
The worker flushes batches before resolving future barriers, tracks failed or incomplete writes, handles cancelled futures, completes barrier tasks, and drains the queue during shutdown.
Sync response and validation
util/eval_pipeline/src/eval_pipeline/headless_backend.py, util/eval_pipeline/tests/test_headless_sync.py
/v1/sync returns HTTP 500 after prior persistence failures. Tests validate ordering, later-arrival exclusion, writer failures, skipped payloads, and cancelled requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 87043

The headless sync endpoint now waits for earlier persistence work and reports write failures; targeted coverage indicates the intended ordering, failure, cancellation, and shutdown behavior is ready to merge.

Sequence Diagram(s)

sequenceDiagram
  participant SyncClient
  participant SyncEndpoint
  participant IngestionQueue
  participant HeadlessWorker
  participant PersistenceWriter
  SyncClient->>SyncEndpoint: POST /v1/sync
  SyncEndpoint->>IngestionQueue: enqueue future barrier
  HeadlessWorker->>PersistenceWriter: persist preceding batches
  PersistenceWriter-->>HeadlessWorker: success or failure
  HeadlessWorker-->>SyncEndpoint: resolve barrier status
  SyncEndpoint-->>SyncClient: HTTP 200 or HTTP 500
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: /v1/sync now acknowledges only after preceding writes complete. The emoji suffix is unnecessary but does not make the title misleading.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Sampoorn Nagpal <nagpalsampoorn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant